<?php
import( 'de.ceus-media.framework.krypton.core.Logic' );
import( 'classes.model.Project' );
import( 'classes.model.ServerProject' );
//import( 'de.ceus-media.framework.krypton.core.database.StatementBuilder' );
/**
 *	Logic of Licencee, Locations and Companies.
 *	@package		mv2.logic
 *	@extends		Framework_Krypton_Core_Logic
 *	@author			Christian Würker <Christian.Wuerker@CeuS-Media.de>
 *	@author			David Seebacher <dseebacher@gmail.com>
 *	@since			13.03.2007
 *	@version		0.1
 */
/**
 *	Logic of Licencee, Locations and Companies.
 *	@package		mv2.logic
 *	@extends		Framework_Krypton_Core_Logic
 *	@author			Christian Würker <Christian.Wuerker@CeuS-Media.de>
 *	@author			David Seebacher <dseebacher@gmail.com>
 *	@since			13.03.2007
 *	@version		0.1
 */
class Logic_Project extends Framework_Krypton_Core_Logic
{
	function addProject( $data, $prefix = "" )
	{
		$data	= $this->removePrefixFromFields( $data, $prefix );
		$this->validateForm( 'administration/project', 'addProject', $data, $prefix );
		$data['created']	= time();
		$model	= new Model_Project();
		return $model->insert( $data );
	}
		
	function editProject( $projectId, $data, $prefix = "" )
	{
		if( !$projectId )
		 	throw new Framework_Krypton_Exception_Logic( 'project_id_missing' );
		$model	= new Model_Project( $projectId );
		if( !$model->exists() )
			throw new Framework_Krypton_Exception_Logic( 'invalid_project_id' );
		$data	= $this->removePrefixFromFields( $data, $prefix );
		$this->validateForm( 'administration/project', 'editProject', $data, $prefix );
		$result	= $model->update( $data );
		if( $result )
			$model->update( array( 'modified' => time() ) );
		return $result;
	}

	static function getProjectData( $projectId )
	{
		$model	= new Model_Project( $projectId );
		$data	= $model->get();
		if( !$data )
			throw new Framework_Krypton_Exception_Logic( 'invalid_project_id' );
		return $data;
	}
	
	static function getProjectDescription( $projectId )
	{
		$data	= self::getProjectData( $projectId );
		return $data['description'];
	}
	
	static function getProjectList( $assoc = false )
	{
		$projects	= array();
		$model	= new Model_Project();
		$list	= $model->find();
		return $list;
	}
	
	static function getProjects( $assoc = false )
	{
		$projects	= array();
		$model	= new Model_Project();
		$list	= $model->find();
		foreach( $list as $entry )
			$projects[$entry['project_id']]	= $entry['title'];
		return $projects;
	}
	
	static function getProjectTitle( $projectId )
	{
		$data	= self::getProjectData( $projectId );
		return $data['title'];
	}
}
?>
